home *** CD-ROM | disk | FTP | other *** search
- '\"
- '\" Copyright (c) 1989-1993 The Regents of the University of California.
- '\" All rights reserved.
- '\"
- '\" Permission is hereby granted, without written agreement and without
- '\" license or royalty fees, to use, copy, modify, and distribute this
- '\" documentation for any purpose, provided that the above copyright
- '\" notice and the following two paragraphs appear in all copies.
- '\"
- '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
- '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
- '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- '\"
- '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- '\" AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- '\"
- '\" $Header: /user6/ouster/tcl/man/RCS/CrtMathFnc.3,v 1.1 93/04/14 16:35:59 ouster Exp $ SPRITE (Berkeley)
- '\"
- '\"----------------------------------------------------------------------------
- '\" @(#) CrtMathFnc.3 26.1 93/10/22 SCOINC
- '\"
- '\" Copyright (C) The Santa Cruz Operation, 1992-1993.
- '\" This Module contains Proprietary Information of
- '\" The Santa Cruz Operation, and should be treated as Confidential.
- '\"----------------------------------------------------------------------------
- .so ../man.macros
- .HS Tcl_CreateMathFunc tclc 7.0
- .BS
- .SH NAME
- Tcl_CreateMathFunc \- Define a new math function for expressions
- .SH SYNOPSIS
- .nf
- \fB#include <tcl.h>\fR
- .sp
- \fBTcl_CreateMathFunc\fR(\fIinterp, name, numArgs, argTypes, proc, clientData\fR)
- .SH ARGUMENTS
- .AS Tcl_ValueType clientData
- .AP Tcl_Interp *interp in
- Interpreter in which new function will be defined.
- .AP char *name in
- Name for new function.
- .AP int numArgs in
- Number of arguments to new function; also gives size of \fIargTypes\fR array.
- .AP Tcl_ValueType *argTypes in
- Points to an array giving the permissible types for each argument to
- function.
- .AP Tcl_MathProc *proc in
- Procedure that implements the function.
- .AP ClientData clientData in
- Arbitrary one-word value to pass to \fIproc\fR when it is invoked.
- .BE
-
- .SH DESCRIPTION
- .PP
- Tcl allows a number of mathematical functions to be used in
- expressions, such as \fBsin\fR, \fBcos\fR, and \fBhypot\fR.
- \fBTcl_CreateMathFunc\fR allows applications to add additional functions
- to those already provided by Tcl or to replace existing functions.
- \fIName\fR is the name of the function as it will appear in expressions.
- If \fIname\fR doesn't already exist as a function then a new function
- is created. If it does exist, then the existing function is replaced.
- \fINumArgs\fR and \fIargTypes\fR describe the arguments to the function.
- Each entry in the \fIargTypes\fR array must be either TCL_INT, TCL_DOUBLE,
- or TCL_EITHER to indicate whether the corresponding argument must be an
- integer, a double-precision floating value, or either, respectively.
- .PP
- Whenever the function is invoked in an expression Tcl will invoke
- \fIproc\fR. \fIProc\fR should have arguments and result that match
- the type \fBTcl_MathProc\fR:
- .nf
- .RS
- typedef int Tcl_MathProc(
- .RS
- ClientData \fIclientData\fR,
- Tcl_Interp *\fIinterp\fR,
- Tcl_Value *\fIargs\fR,
- Tcl_Value *resultPtr\fR);
- .RE
- .RE
- .fi
- .PP
- When \fIproc\fR is invoked the \fIclientData\fR and \fIinterp\fR
- arguments will be the same as those passed to \fBTcl_CreateMathFunc\fR.
- \fIArgs\fR will point to an array of \fInumArgs\fR Tcl_Value structures,
- which describe the actual arguments to the function:
- .nf
- .RS
- typedef struct Tcl_Value {
- .RS
- Tcl_ValueType \fItype\fR;
- int \fIintValue\fR;
- double \fIdoubleValue\fR;
- .RE
- } Tcl_Value;
- .RE
- .fi
- .PP
- The \fItype\fR field indicates the type of the argument and is
- either TCL_INT or TCL_DOUBLE.
- It will match the \fIargTypes\fR value specified for the function unless
- the \fIargTypes\fR value was TCL_EITHER. Tcl converts
- the argument supplied in the expression to the type requested in
- \fIargTypes\fR, if that is necessary.
- Depending on the value of the \fItype\fR field, the \fIintValue\fR
- or \fIdoubleValue\fR field will contain the actual value of the argument.
- .PP
- \fIProc\fR should compute its result and store it either as an integer
- in \fIresultPtr->intValue\fR or as a floating value in
- \fIresultPtr->doubleValue\fR.
- It should set also \fIresultPtr->type\fR to either TCL_INT or TCL_DOUBLE
- to indicate which value was set.
- Under normal circumstances \fIproc\fR should return TCL_OK.
- If an error occurs while executing the function, \fIproc\fR should
- return TCL_ERROR and leave an error message in \fIinterp->result\fR.
-
- .SH KEYWORDS
- expression, mathematical function
-